#!/usr/bin/python3

from rest_framework import serializers

from apps.blog.models import Collect, province
from apps.message_form.models import Message


class MessageSerializer(serializers.ModelSerializer):

    class Meta:
        model = Message  # 写法和上面的CourseForm类似
        # exclude = ('id', )  # 注意元组中只有1个元素时不能写成("id")
        # fields = ('id', 'name', 'introduction', 'teacher', 'price', 'created_at', 'updated_at')
        fields = ('name', 'value')


# 饼图
class HotSerializer(serializers.ModelSerializer):

    class Meta:
        model = Message  # 写法和上面的CourseForm类似
        fields = ('name', 'value')


# 圆图
class StockSerializer(serializers.ModelSerializer):

    class Meta:
        model = Collect  # 写法和上面的CourseForm类似
        fields = ('name', 'stock','value')

class CitySerializer(serializers.ModelSerializer):
    type = serializers.Field()


# 地图
class MapSerializer(serializers.ModelSerializer):
    # city = serializers.Field(source='name')
    # lat = serializers.Field(source="message.lat")
    # lng = serializers.Field(source="message.lng")

    class Meta:
        model = Collect  # 写法和上面的CourseForm类似
        fields = ('name','value')


# 柱状图
class SellerSerializer(serializers.ModelSerializer):

    class Meta:
        model = Collect  # 写法和上面的CourseForm类似
        fields = ('name', 'value')


# 柱状图
class RankSerializer(serializers.ModelSerializer):

    class Meta:
        model = province  # 写法和上面的CourseForm类似
        fields = ('name', 'value')


# 折线图
class TrendSerializer(serializers.ModelSerializer):

    class Meta:
        model = Collect  # 写法和上面的CourseForm类似
        fields = ('name', 'value')


# class CourseSerializer(serializers.HyperlinkedModelSerializer):
#     teacher = serializers.ReadOnlyField(source='teacher.username')
#
#     class Meta:
#         model = Course
#         # url是默认值，可在settings.py中设置URL_FIELD_NAME使全局生效
#         fields = ('id', 'url', 'name', 'introduction', 'teacher', 'price', 'created_at', 'updated_at')